package Exc.service.impl;

import Exc.domain.IPMessage;
import Exc.domain.PageResult;
import Exc.domain.QueryObject;
import Exc.mapper.IpMessageMapper;
import Exc.service.IIpMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * The type IpMessage service.
 *
 * @author fengke
 */
@Service
public class IpMessageServiceImpl implements IIpMessageService {
    @Autowired
    private IpMessageMapper ipMessageMapper;

    @Override
    public PageResult<IPMessage> queryIpMessageByPage(QueryObject queryObject) {
        int totalCount = ipMessageMapper.selectCount();
        PageResult<IPMessage> pageResult = null;
        if (totalCount == 0) {
            pageResult = new PageResult<>(queryObject.getCurrentPage(),queryObject.getPageSize(),
                    0,new ArrayList<IPMessage>());
        } else {
            List<IPMessage> ipMessageList = ipMessageMapper.selectIPMessage(queryObject);
            pageResult = new PageResult<>(queryObject.getCurrentPage(), queryObject.getPageSize(),
                    totalCount, ipMessageList);
        }
        return pageResult;
    }
}
